package lu.med.praxiswahl.wahlumed.dao.beans;

import java.util.List;
import javax.ejb.Local;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import lu.med.praxiswahl.wahlumed.dao.beans.daointerface.OPCodeRateDAOInt;
import lu.med.praxiswahl.wahlumed.model.beans.OPCodeRateTBL;

/**
 * Session Bean implementation class OPCodeRateDAO
 */
@Stateless
@Local(
{ OPCodeRateDAOInt.class })
public class OPCodeRateDAO implements OPCodeRateDAOInt
{
    @PersistenceContext(unitName = "gynaekomedic-ejbPU")
    private EntityManager em = null;

    /**
     * Default constructor.
     */
    public OPCodeRateDAO()
    {
	// TODO Auto-generated constructor stub
    }

    @Override
    public void delete(String to_delete)
    {
	OPCodeRateTBL coRates = em.find(OPCodeRateTBL.class, to_delete);
	em.remove(coRates);
	em.flush();

    }

    @SuppressWarnings("unchecked")
    @Override
    public List<OPCodeRateTBL> getAvailableOPCodeRates()
    {

	Query query = em.createNamedQuery("getAvailableOPCodeRates");

	return (List<OPCodeRateTBL>) query.getResultList();
    }

    @Override
    public void persist(OPCodeRateTBL to_persist)
    {
	em.persist(to_persist);
	em.flush();

    }

    @Override
    public OPCodeRateTBL retrieveOPCodeRateByID(String label)
    {
	return (OPCodeRateTBL) em.find(OPCodeRateTBL.class, label);
    }

    @Override
    public void update(OPCodeRateTBL to_update)
    {
	em.merge(to_update);
	em.flush();

    }

}
